import java.util.TreeMap;

/**
 * @author hewei
 * @version 1.0
 * @description: 1146. 快照数组
 * @date 2022/11/3 21:41
 */

public class SnapshotArray {

    int length;
    int curSnapId;
    TreeMap<Integer, Integer>[] lists;

    public SnapshotArray(int length) {
        curSnapId = -1;
        this.length = length;
        lists = new TreeMap[length];
        for (int i = 0; i < length; i++) {
            lists[i] = new TreeMap<>();
            lists[i].put(curSnapId, 0);
        }
    }

    public void set(int index, int val) {
        lists[index].put(curSnapId, val);
    }

    public int snap() {
        ++curSnapId;
        return curSnapId;
    }

    public int get(int index, int snap_id) {
        return lists[index].lowerEntry(snap_id).getValue();
    }
}
